package com.system.business.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.system.business.domain.ConfirmOrder;
import com.system.business.domain.Station;
import com.system.business.mapper.ConfirmOrderMapper;
import com.system.business.req.ConfirmOrderQueryReq;
import com.system.business.req.ConfirmOrderSaveReq;
import com.system.business.req.StationQueryReq;
import com.system.business.req.StationSaveReq;
import com.system.business.resp.ConfirmOrderQueryResp;
import com.system.business.resp.StationQueryResp;
import com.system.business.service.StationService;
import com.system.business.mapper.StationMapper;
import com.system.common.resp.PageResp;
import com.system.common.utils.SnowUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Admin
* @description 针对表【station(车站)】的数据库操作Service实现
* @createDate 2024-03-21 15:02:15
*/
@Service
public class StationServiceImpl extends ServiceImpl<StationMapper, Station>
    implements StationService{

    @Autowired
    private StationMapper stationMapper;
    @Override
    public PageResp<StationQueryResp> queryList(StationQueryReq req) {
        Page<Station> pageCondition = new Page<>(req.getPage(), req.getSize());
        QueryWrapper<Station> passengerQueryWrapper = new QueryWrapper<>();
        Page<Station> pageData = stationMapper.selectPage(pageCondition,passengerQueryWrapper);
        List<StationQueryResp> list = BeanUtil.copyToList(pageData.getRecords(), StationQueryResp.class);

        PageResp<StationQueryResp> pageResp = new PageResp<>();
        pageResp.setTotal(pageData.getTotal());
        pageResp.setList(list);
        return pageResp;
    }
    @Override
    public void save(StationSaveReq req) {
        DateTime now = DateTime.now();

        Station station = BeanUtil.copyProperties(req, Station.class);
        if (ObjectUtil.isNull(station.getId())) {
            station.setId(SnowUtil.getSnowflakeNextId());
            station.setUpdateTime(now);
            station.setCreateTime(now);
            stationMapper.insert(station);
        } else {
            station.setUpdateTime(now);
            stationMapper.updateById(station);
        }
    }
}




